class Person {
  constructor(public name: string, private _age: number) {
    this.name = name;
    this._age = _age;
  }

  get age() {
    return this._age;
  }

  set age(val: number) {
    if (val > 100 || val < 0) {
      throw new Error("年龄不在合适的范围");
    } else {
      this._age = val;
    }
  }
}

let p: Person = new Person("zs", 11);
p.age = -1;

console.log(p.age);

export {};
